package com.ls.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ls.blog.dto.Recodes;
import com.ls.blog.entity.Tag;
import com.ls.blog.mapper.TagMapper;
import com.ls.blog.service.TagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ls.blog.utils.PageUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lishun
 * @since 2022-01-14
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {

    @Resource
    private TagMapper tagMapper;

    @Override
    public Recodes<Tag> pageTags(Long current, Long size) {
        Page<Tag> page = new Page<>(current,size);
        tagMapper.selectPage(page,new LambdaQueryWrapper<>());
        return PageUtils.page(page);
    }

    @Override
    public List<Tag> getTagByName(String name) {
        return this.list(new LambdaQueryWrapper<Tag>().like(Tag::getName,name));
    }

    @Override
    public void updateTag(Tag tag) {
        this.updateById(tag);
    }

    @Override
    public void deleteTagById(Long id) {
        this.removeById(id);
    }

    @Override
    public Tag getTagById(Long id) {
        return this.getById(id);
    }
}
